﻿namespace BEGDC.CC.Web.EZVisit.Controls
{
    #region Using Directives

    using System;
    using System.Web.UI;

    #endregion

    public partial class EZVRequestBasicInfo : UserControl
    {
        public string SessionKey
        {
            get
            {
                return Convert.ToString(this.ViewState["SessionKey"]);
            }
            set
            {
                this.ViewState["SessionKey"] = value;
            }
        }

        public string CurrentUser
        {
            get
            {
                return Convert.ToString(this.ViewState["CurrentUser"]);
            }
            set
            {
                this.ViewState["CurrentUser"] = value;
            }
        }

        public EZVisitAccessControl AccessControl { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Visible && !this.IsPostBack)
            {
                this.SetView();
            }
        }

        private void SetView()
        {
            this.SetApplicantView();
            this.SetContractView();
            this.SetVisitPlacesView();
            this.SetCustomerView();
            this.SetAltAttendeeView();
            this.SetQuotAttchView();
            this.SetAftReturnView();
            this.SetAttchView();
        }

        #region Applicant

        private void SetApplicantView()
        {
            if (!this.AccessControl.ApplicationTabView.Visible)
            {
                return;
            }

            this.pnlApplicant.Visible = this.ucApplicant.Visible = true;
            this.ucApplicant.SessionKey = this.SessionKey;
            this.ucApplicant.Editable = false;
            this.ucApplicant.CurrentUser = CurrentUser;
        }

        #endregion Applicant

        #region Contract

        private void SetContractView()
        {
            this.pnlContract.Visible = this.ucContract.Visible = this.AccessControl.ContractTabView.Visible;
            this.ucContract.SessionKey = this.SessionKey;
            this.ucContract.Editable = false;
            this.ucContract.CurrentUser = this.CurrentUser;
        }

        #endregion

        #region Visit Places

        private void SetVisitPlacesView()
        {
            if (!this.AccessControl.ApplicationTabView.Visible)
            {
                return;
            }

            this.pnlVisit.Visible = this.ucVisit.Visible = true;
            this.ucVisit.SessionKey = this.SessionKey;
            this.ucVisit.Editable = false;
            this.ucVisit.CurrentUser = this.CurrentUser;
        }

        #endregion

        #region Customers

        private void SetCustomerView()
        {
            if (!this.AccessControl.ApplicationTabView.Visible)
            {
                return;
            }

            this.pnlCustomer.Visible = this.ucCustomer.Visible = true;
            this.ucCustomer.SessionKey = this.SessionKey;
            this.ucCustomer.Editable = false;
            this.ucCustomer.CurrentUser = this.CurrentUser;
        }

        #endregion

        #region Alt Attendees

        private void SetAltAttendeeView()
        {
            if (!this.AccessControl.ApplicationTabView.Visible)
            {
                return;
            }

            this.pnlAttendees.Visible = this.ucAltAttendee.Visible = true;
            this.ucAltAttendee.SessionKey = this.SessionKey;
            this.ucAltAttendee.Editable = false;
            this.ucAltAttendee.CurrentUser = this.CurrentUser;
        }

        #endregion

        #region Quotation Attachment

        private void SetQuotAttchView()
        {
            // Tab 7
            this.pnlQuotAttch.Visible = this.ucQuotAttch.Visible = this.AccessControl.QuotAttchTabView.Visible;
            this.ucQuotAttch.Editable = false;
            this.ucQuotAttch.CurrentUser = this.CurrentUser;
            this.ucQuotAttch.SessionKey = this.SessionKey;
        }

        #endregion

        #region AftReturn

        private void SetAftReturnView()
        {
            bool tabVisible = this.AccessControl.AftReturnTabsView.Visible;

            this.pnlFeedback.Visible = this.ucFeedback.Visible = tabVisible;
            this.pnlAftReturn.Visible = this.ucAftAttchment.Visible = tabVisible;
            this.ucFeedback.SessionKey = this.ucAftAttchment.SessionKey = this.SessionKey;
            this.ucFeedback.Editable = this.ucAftAttchment.Editable = false;
            this.ucFeedback.CurrentUser = this.ucAftAttchment.CurrentUser = this.CurrentUser;
        }

        #endregion

        #region Attchments

        private void SetAttchView()
        {
            if (!this.AccessControl.ApplicationTabView.Visible)
            {
                return;
            }

            this.pnlAttch.Visible = this.ucAttachment.Visible = true;
            this.ucAttachment.Editable = false;
            this.ucAttachment.SessionKey = this.SessionKey;
            this.ucAttachment.CurrentUser = this.CurrentUser;
        }

        #endregion
    }
}